package com.yyfax.ph.common;

import android.content.Context;
import android.text.TextUtils;

import com.yyfax.common.tools.DeviceUuidFactory;
import com.yyfax.common.tools.SystemTool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* 全局共享变量配置类
 *
 * 多个功能模块间共用的变量或方法，放置于这里，定义的变量尽量设置为private，不要直接public引用操作。
 *
* @author ying_he
* @date 2017/3/17 8:59
*/
public class GlobalVariableConfig {
    private static String sMacId;
    private static String sVersion;
    private static String sKeyRSA;
    private static boolean sIgnoreGesture = false; //忽略手势
    private static boolean sThirdPartyPageOpened = false; //是否打开了本app之外的界面

    private static class SingletonHolder{
        private static final ExecutorService sCachedThreadPool = Executors.newCachedThreadPool();
    }

    /**
     * 使用线程池管理Runnable
      */
    public static ExecutorService getExecutorService() {
        return SingletonHolder.sCachedThreadPool;
    }

    public static String getMacId(Context context){
        if (TextUtils.isEmpty(sMacId)){
            sMacId = DeviceUuidFactory.getDeviceUuid(context.getApplicationContext());
        }
        return sMacId;
    }

    public static String getVersionCode(Context context){
        if (TextUtils.isEmpty(sVersion)){
            sVersion = SystemTool.getAppVersionCode(context.getApplicationContext()) + "";
        }
        return sVersion;
    }

    public static String getKeyRSA(){
        return sKeyRSA;
    }

    public static void setKeyRSA(String keyRSA){
        sKeyRSA = keyRSA;
    }

    /**
     * 是否忽略手势密码
     * @param flag
     */
    public static void setIgnoreGestureFlag(boolean flag){
        sIgnoreGesture = flag;
    }

    /**
     * 是否忽略手势密码
     * @return
     */
    public static boolean hasIgnoreGestureFlag(){
        return sIgnoreGesture;
    }

    /**
     * 是否打开了本app以外的界面
     * @param flag
     */
    public static void setThirdPartyPageOpenedFlag(boolean flag){
        sThirdPartyPageOpened = flag;
    }

    /**
     * 是否打开了本app以外的界面
     * @return
     */
    public static boolean isThirdPartyPageOpened(){
        return sThirdPartyPageOpened;
    }

}
